package eu.webhib.webblog.domain;

//
public class UserRole {
   //
   private static final char USER_ROLE_ADMIN = 'A';
   private static final char USER_ROLE_BLOGGER = 'B';
   private static final char USER_ROLE_COMMENTER = 'C';
   //
   private static UserRole adminRole = new UserRole(USER_ROLE_ADMIN);
   private static UserRole bloggerRole = new UserRole(USER_ROLE_BLOGGER);
   private static UserRole commenterRole = new UserRole(USER_ROLE_COMMENTER);
   //
   private char roleId;

   public static UserRole getAdminRole() {
      return adminRole;
   }

   public static UserRole getBloggerRole() {
      return adminRole;
   }

   static UserRole getRoleById(Character roleId) {
      assert (roleId != null);
      switch (roleId.charValue()) {
         case USER_ROLE_ADMIN:
            return adminRole;
         case USER_ROLE_BLOGGER:
            return bloggerRole;
         case USER_ROLE_COMMENTER:
            return commenterRole;
      }
      assert (false);
      return null;
   }

   protected UserRole(char roleId) {
      this.roleId = roleId;
   }

   public Character getRoleId() {
      return roleId;
   }

   public boolean isAdminRight() {
      return roleId == USER_ROLE_ADMIN;
   }
}
